﻿<Window x:Class="_12.BindToList.Group"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:_12.BindToList"
        xmlns:p11="clr-namespace:_11.DataBinding;assembly=11.DataBinding"
        Title="Group" Height="254" Width="470">
    <Window.Resources>
        <local:PersonCollection x:Key="persons">
            <p11:Person Age="10" Name="Henry"/>
            <p11:Person Age="40" Name="Mary"/>
            <p11:Person Age="40" Name="Mary's Husband"/>
            <p11:Person Age="70" Name="Alice"/>
            <p11:Person Age="60" Name="Dick"/>
            <p11:Person Age="60" Name="Dick's Wife"/>
        </local:PersonCollection>
        <Style TargetType="Button">
            <Setter Property="Margin" Value="5"/>
            <Setter Property="Background" Value="LightGreen"/>
        </Style>
        <GroupStyle x:Key="customGrpStyle">
            <GroupStyle.HeaderTemplate>
                <DataTemplate>
                    <TextBlock Background="Black" Foreground="White" FontWeight="Bold">
                        <TextBlock Text="{Binding Path=Name}"/>
                        (<TextBlock Text="{Binding Path=ItemCount}"/>)
                    </TextBlock>
                </DataTemplate>
            </GroupStyle.HeaderTemplate>
        </GroupStyle>
    </Window.Resources>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="4*" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <ListBox Grid.ColumnSpan="3" Margin="5" 
                 Name="lbxPersons"
                 ItemsSource="{StaticResource persons}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock>
                        <TextBlock Text="{Binding Path=Name}"/>
                        (age:
                        <TextBlock Text="{Binding Path=Age}"/>)
                    </TextBlock>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
        <Button Content="Default Group Style" Grid.Row="1"
                Name="btnDefGroup"
                Click="btnDefGroup_Click"/>
        <Button Content="Custom Group Style" Grid.Row="1" Grid.Column="1" 
                Name="btnCustGroup"
                Click="btnCustGroup_Click"/>
        <Button Content="Group By Range" Grid.Row="1" Grid.Column="2"
                Name="btnRangeGroup"
                Click="btnRangeGroup_Click"/>
    </Grid>
</Window>
